package com.glsc.ngateway.platform.controller.it.project;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.api.common.dto.PageQueryParamDto;
import com.glsc.ngateway.common.api.platform.dto.it.project.ProjectDto;
import com.glsc.ngateway.platform.service.it.project.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;


/**
 * @author xuchang
 */
@RestController
@RequestMapping("/it/project")
@Api(value = "项目管理", tags = {"项目管理"})
public class ProjectController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProjectController.class);

    @Autowired
    private ProjectService projectService;

    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "新增或修改", notes = "新增或修改")
    public PlatformResponse<Void> addOrUpdate(@RequestBody ProjectDto projectDto) {
        projectService.addOrUpdate(projectDto);
        return PlatformResponse.successMsg("操作成功");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public PlatformResponse<Void> delete(@RequestBody ProjectDto param) throws Exception {
        if (Objects.isNull(param.getId())) {
            return PlatformResponse.failedMsg("删除失败：参数id为空。");
        }
        projectService.delete(param.getId());
        return PlatformResponse.successMsg("删除成功");
    }

    @PostMapping("/search")
    @ApiOperation(value = "查询", notes = "查询")
    public PlatformResponse<Page<ProjectDto>> search(@RequestBody PageQueryParamDto<ProjectDto> params) {
        Page<ProjectDto> result = projectService.query(params);
        return PlatformResponse.successData(result);
    }

}